//
//  LeftMenuViewController.m
//  Remind
//
//  Created by mac on 2017/10/6.
//  Copyright © 2017年 2017.09.27. All rights reserved.
//

#import "LeftMenuViewController.h"
#import "LeftMenuTableViewCell.h"
#import "SettingViewController.h"
#import "MainViewController.h"
#import "AboutViewController.h"
#import "UIViewController+LGSideMenuController.h"
#import "LGSideMenuController.h"
#import "AppDelegate.h"
#import "DataCach.h"

#define NAVCON_COLOR [UIColor whiteColor]
@interface LeftMenuViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    NSArray *titleArr;
}

@end

@implementation LeftMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    titleArr = @[@"主页",@"设置",@"关于"];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, self.view.frame.size.height) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"LeftMenuTableViewCell" bundle:nil] forCellReuseIdentifier:@"leftMenuCell"];
    
    [self.view addSubview:self.tableView];
    
    UIImageView *headImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 200)];
    headImgView.backgroundColor = [UIColor blackColor];
    
    UILabel *textLabel = [[UILabel alloc] init];
    textLabel.text = @"Remind";
    textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:35];
    textLabel.textColor = [UIColor whiteColor];
    [textLabel sizeToFit];
    textLabel.center = CGPointMake(headImgView.frame.size.width / 2, headImgView.frame.size.height / 2);
    [headImgView addSubview:textLabel];
    
    self.tableView.tableHeaderView = headImgView;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LeftMenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"leftMenuCell"];
    cell.contentLabel.text = titleArr[indexPath.row];
    cell.imgView.image = [UIImage imageNamed:titleArr[indexPath.row]];
    cell.backgroundColor = indexPath.row == _idx?[UIColor colorWithWhite:0.8 alpha:1.0]:[UIColor whiteColor];
    
    return cell;
}

#pragma mark - Select
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        
        MainViewController *mainCon = [[MainViewController alloc] init];
        [DataCach selectSideMenuPushViewController:mainCon Index:0];

        
    }else if(indexPath.row == 1){
        
        SettingViewController *setCon = [[SettingViewController alloc] init];
        [DataCach selectSideMenuPushViewController:setCon Index:1];

        
    }else if(indexPath.row == 2){
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        AboutViewController *aboutCon = [story instantiateViewControllerWithIdentifier:@"about"];
        [DataCach selectSideMenuPushViewController:aboutCon Index:2];
        
    }
}

- (void)pushViewController:(UIViewController *)viewCon{
    LGSideMenuController *sideMenuCon = [self sideMenuController];
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [appDelegate.shadownView removeFromSuperview];
    
    [viewCon.view addSubview:appDelegate.shadownView];
    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:viewCon];
    navCon.navigationBar.barTintColor = NAVCON_COLOR;
    sideMenuCon.rootViewController = navCon;
    [sideMenuCon hideLeftViewAnimated:YES completionHandler:nil];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return titleArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55;
}

//- (BOOL)prefersStatusBarHidden {
//    return YES;
//}
//
//- (UIStatusBarStyle)preferredStatusBarStyle {
//    return UIStatusBarStyleDefault;
//}
//
//- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
//    return UIStatusBarAnimationFade;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
